package com.zh.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.pojo.bo.OrderToDriverBo;
import com.zh.pojo.domain.Order;
import com.zh.pojo.dto.ConfirmAmountDto;
import com.zh.pojo.dto.DriverLocationDto;
import com.zh.pojo.dto.OrderDto;
import com.zh.pojo.query.PageQueryWrapper;
import com.zh.pojo.vo.KillOrderVo;
import com.zh.result.JSONResult;
import com.zh.result.PageResult;
import com.zh.service.IOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Tag(name = "订单表",description = "订单表")
@RestController
@RequestMapping("app/order")
public class AppOrderController {

    @Autowired
    public IOrderService orderService;

    @Operation( summary= "创建订单",description = "创建订单")
    @Parameter(name = "order",description = "保存的对象",required = true)
    @PostMapping("/createOrder")
    public JSONResult createOrder(@RequestBody @Valid OrderDto orderDto){
        String orderNo = orderService.createOrder(orderDto);
        return JSONResult.success(orderNo);
    }
    @Operation( summary= "司机拉取订单",description = "司机拉取订单")
    @GetMapping("/driver/pullNewOrders")
    public JSONResult pullNewOrders(){
        List<OrderToDriverBo> boList = orderService.pullNewOrders();
        return JSONResult.success(boList);
    }
    @Operation( summary= "司机抢单",description = "司机抢单")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @PostMapping("/killOrder/{orderNo}")
    public JSONResult killOrder(@PathVariable String orderNo){
        KillOrderVo killOrderVo = orderService.killOrder(orderNo);
        return JSONResult.success(killOrderVo);
    }
    @Operation( summary= "乘客自动取消订单",description = "乘客自动取消订单")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @PostMapping("/autoCancelOrder/{orderNo}")
    public JSONResult autoCancelOrder(@PathVariable String orderNo){
       orderService.autoCancelOrder(orderNo);
        return JSONResult.success();
    }
    @Operation( summary= "司机加载进行中的订单",description = "司机加载进行中的订单")
    @GetMapping("OrdersInProgress/driver")
    public JSONResult OrdersInProgress(){
        return JSONResult.success(orderService.OrdersInProgressToDriver());
    }


    @Operation(summary = "加载乘客进行中的订单", description = "加载乘客进行中的订单")
    @GetMapping("/customer/inprocess")
    public JSONResult selectCustomerInProcessOrder() {
        return JSONResult.success(orderService.selectCustomerInProcessOrder());
    }

    @Operation( summary= "缓存司机坐标、订单号、订单状态",description = "缓存司机坐标、订单号、订单状态")
    @PostMapping(value = "/cache/location/point")
    public JSONResult cacheLocationPoint(@RequestBody @Valid DriverLocationDto locationDto){
        orderService.cacheLocationPoint(locationDto);
        return JSONResult.success();
    }

    @Operation(summary = "拉取司机位置，订单号，订单状态", description = "拉取司机位置，订单号，订单状态")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @GetMapping("/pull/driverLocation/{orderNo}")
    public JSONResult pullDriverLocation(@PathVariable @Valid String orderNo) {
        return JSONResult.success(orderService.pullDriverLocation(orderNo));
    }
    @Operation(summary = "加载订单的位置", description = "加载订单的位置，订单号，订单状态")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @GetMapping("/load/orderLocatin/{orderNo}")
    public JSONResult loadOrderLocatin(@PathVariable @Valid String orderNo) {
        return JSONResult.success(orderService.loadOrderLocatin(orderNo));
    }

    @Operation(summary = "司机到达代驾点", description = "司机到达代驾点")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @PostMapping("/driverArrive/{orderNo}")
    public JSONResult driverArrive(@PathVariable @Valid String orderNo) {
        orderService.driverArrive(orderNo);

        return JSONResult.success();
    }
    @Operation(summary = "司机开始代驾", description = "司机开始代驾")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @PostMapping("/startDriving/{orderNo}")
    public JSONResult startDriving(@PathVariable @Valid String orderNo) {
        orderService.startDriving(orderNo);
        return JSONResult.success();
    }
    @Operation(summary = "司机结束代驾", description = "司机结束代驾")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @PostMapping("/endDriving/{orderNo}")
    public JSONResult endDriving(@PathVariable @Valid String orderNo) {
        orderService.endDriving(orderNo);
        return JSONResult.success();
    }
    @Operation(summary = "司机确认费用", description = "司机确认费用")
    @PostMapping("/confirmAmount")
    public JSONResult confirm(@RequestBody @Valid ConfirmAmountDto confirmAmountDto) {
        orderService.confirm(confirmAmountDto);
        return JSONResult.success();
    }
    @Operation(summary = "司机查询订单账单表", description = "司机查询订单账单表")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @GetMapping("/driver/orderbill/{orderNo}")
    public JSONResult selectDriverOrderBill(@PathVariable @Valid String orderNo) {
        return JSONResult.success(orderService.selectDriverOrderBill(orderNo));
    }
    @Operation(summary = "司机发送账单", description = "司机发送账单")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @PostMapping("/payorder/send/{orderNo}")
    public JSONResult sendPayOrder(@PathVariable @Valid String orderNo) {
        orderService.sendPayOrder(orderNo);
        return JSONResult.success();
    }
    @Operation(summary = "乘客查询订单账单表", description = "乘客查询订单账单表")
    @Parameter(name = "orderNo",description = "订单号",required = true)
    @GetMapping("/customer/orderbill/{orderNo}")
    public JSONResult selectCustomerOrderBill(@PathVariable @Valid String orderNo) {
        return JSONResult.success(orderService.selectCustomerOrderBill(orderNo));
    }
}
